public with sharing class LoanRequest extends AbstractBean
{
    
    public boolean submitted {get;set;}
    
    public String referrerCode {get;set;}
    
    public String referrerCodeOther {get;set;}
    
    public String salutation {get;set;}
    
    public String securityOffered {get;set;}
    
    public String securityOfferedOther {get;set;}
    
    public String securityAmount {get;set;}
    
    public boolean termsAndConditions {get;set;}
    
    public String currentBank {get;set;}
    
    public List<Loan> loans{get;set;}

    public String firstName{get;set;}
   
    public String lastName {get;set;}
    
    public String company {get;set;}
    
    public String loanType {get;set;}
    
    public String email {get;set;}
    
    public String phone {get;set;}
    
    public String address1 {get;set;}
    
    public String suburb {get;set;}
    
    public String country {get;set;}
    
    public String state {get;set;}
    
    public String postcode {get;set;}
    
    public String amount {get;set;}
    
    public String duration {get;set;}
    
    public String timeFrame {get;set;}
    
    public String preferredContactTime {get;set;}
    
    public boolean permissionToSubmit {get;set;}
    
    public String additionalInfo {get;set;}
    
    public String referredBy {get;set;}
    
    public Double getAmountAsDouble()
    {
        if(CommonUtils.isNotBlank(amount))
        {
            return getDouble(amount);
        }
        return null;
    }
    
    public Double getSecurityAmountAsDouble()
    {
        if(CommonUtils.isNotBlank(securityAmount))
        {
            return getDouble(securityAmount);
        }
        return null;
    }
    
    public Account getFranchise()
    {
        return LoanController.getFranchise(this.referrerCode);      
    }
    
    private Double getDouble(String value)
    {
        try
        {
            return Double.valueOf(value);
        }
        catch(System.Exception e)
        {
            return null;
        }
    }
    
    public LoanRequest()
    {
        this.loans = new List<Loan>();
    }
    
    public boolean getHasSelectedLenders()
    {
        for(Loan loan : loans)
        {
            if(loan.selected)
            {
                return true;
            }
        }
        return false;
    }
}